/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package RestaurantManagement;

/**
 * Abstract class that provides structure 
 * for the billing system
 * @author ashongtical
 */

import java.util.ArrayList;

public abstract class RestaurantBillingSystem {
    // this can not use private because it will be used in subclass
    protected ArrayList<Meal> menu;

   // Constructor to initialize the menu
    public RestaurantBillingSystem() {
        this.menu = new ArrayList<>();
    }

    // Add a meal to the menu
    // meal: The meal to add
    public void addMeal(Meal meal) {
        this.menu.add(meal);
        System.out.println("Added '" + meal.getName() + "' to the menu.");
    }

    // Remove a meal from the menu by name
    // mealName The name of the meal to remove
    // return true if meal was removed, false otherwise
    public boolean removeMeal(String mealName){
        if(menu.isEmpty()){
            System.out.println("can not remove meal from null menu");
            return false;
        }else {
            for(Meal meal : menu){
                if(meal.getName().equals(mealName)){
                    menu.remove(meal);
                    System.out.println("Removed " + mealName + " from the menu.");
                    return true;
                }
            }
            System.out.println("meal: " + mealName + "not found on the menu");
            return  false;
        }
    }

    // Display all meals on the menu
    public void displayMenu(){
        if(menu.isEmpty()){
            System.out.println("The menu is currently empty");
            return;
        }

        System.out.println("\n===== MENU =====");
        for(int i = 0; i < menu.size(); i++){
            System.out.println((i + 1) + ". " + menu.get(i));
        }
        System.out.println("===============");
    }

    // Find a meal on the menu by name
    // mealName: The name of the meal to find
    // The meal if found, null otherwise
    public Meal findMealByName(String mealName){
        for(Meal meal : menu){
            if(meal.getName().equals(mealName)){
                return meal;
            }
        }
        return null;
    }

    // Abstract method for adding a meal for an order
    // mealName The name of the meal to add to the order
    // return boolean indicating success or failure
    public abstract boolean addMealToOrder(String mealName);

    // Abstract method for calculating the bill
    // return The total bill amount
    public abstract double calculateBill();
}
